Return to doc.sitecore.com

Valid for Sitecore 5.2, 5.3
Associating a workflow action with a workflow state

Q: 

Is it possible to associate a workflow action with a workflow state so that it is executed when content reaches this state rather than associating the action with a workflow command which requires manual transition?

A:

This task can be solved by attaching an Item which will invoke the action to the workflow state. This Item should be based on either the Action or Command template.

The following article describes how to attach an action to the workflow command.

http://sdn.sitecore.net/FAQ/API/Cause%20the%20workflow%20to%20invoke%20an%20action.html  

The task stated in the present article requires that the action is attached to a workflow state: 
/upload/sdn5/faq/workflow/worflow state action/workflow_state_action1.jpg

See the description of the two approaches below:

  1. Create an action based on the Command template (templates/System/Tasks/Command)
    /upload/sdn5/faq/workflow/worflow state action/workflow_state_action2.jpg
  2. Create an action based on the Action template (templates/System/Workflow/Action)
    /upload/sdn5/faq/workflow/worflow state action/workflow_state_action3.jpg
     
      

The difference is that when you use the Command template, the method that will be invoked should be specified. In case the Action template is used, the method named Process will be invoked by default, but with this template you can also pass some Parameters with the method arguments. Below is a sample snippet of the CustomWorkflowActions.LogAction class:  

namespace CustomWorkflowActions

{

      public class LogAction

      { 

      public void Process(WorkflowPipelineArgs args)

      {

         Sitecore.Diagnostics.Log.Info("ALERT!" + args.DataItem, this);

      }

      }  

}